package com.yanyan.sannuomin.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;


import com.yanyan.sannuomin.domain.*;
import com.yanyan.sannuomin.result.Result;
import com.yanyan.sannuomin.result.ResultCode;

import com.yanyan.sannuomin.service.SccService;


import com.yanyan.sannuomin.vo8081.PRS;
import com.yanyan.sannuomin.vo8081.SDV;
import com.yanyan.sannuomin.vo8081.tj;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import javax.annotation.Resource;
import java.util.List;

@RequestMapping("/user")
@Api(tags = "检测者管理",description = "提供对医院人员的查询")
@RestController
@CrossOrigin
@EnableSwagger2
public class SccController {
    @Resource
    private SccService SccServiceImpl;

    @RequestMapping(value = "findFY1", method = RequestMethod.GET)
    @ApiOperation(value = "查询用户", notes = "根据条件分页查询", httpMethod = "GET")
    public Result findAccount(Integer page, Integer limit, String searchParams) throws  Exception{
        System.out.println("搜索条件："+searchParams);
        ObjectMapper objectMapper = new ObjectMapper();
        SDV sdv = null;
        if(searchParams != null){
            sdv= objectMapper.readValue(searchParams, SDV.class);
        }
        System.out.println("搜索结果："+sdv);
        Page page1 = PageHelper.startPage(page, limit);
        List<SDV> sdv1 = SccServiceImpl.findSDV(sdv);
        PageInfo pageInfo=new PageInfo(sdv1);
        return Result.ok(ResultCode.SUCCESS,pageInfo.getTotal(),sdv1);

    }


    @ApiOperation(value = "添加数据",notes = "添加",httpMethod ="GET")
    @RequestMapping(value = "jcInsert", method = RequestMethod.GET)
    public Result insert(SccPatient sccPatient){
        System.out.println(sccPatient);
        int add=SccServiceImpl.yhInsert(sccPatient);
        if (add>0){
            System.out.println("添加成功");
        }else{
            System.out.println("添加失败");
        }
        return Result.ok(ResultCode.SUCCESS,add);
    }


    @ApiOperation(value = "修改数据",notes = "修改",httpMethod ="POST")
    @RequestMapping(value = "jcUpdate", method = RequestMethod.POST)
    public Result xg(SccPatient sccPatient){

        int add=SccServiceImpl.xgUpdate(sccPatient);
        if (add>0){
            System.out.println("修改成功");
        }else{
            System.out.println("修改失败");
        }
        return Result.ok(ResultCode.SUCCESS,add);
    }


    @RequestMapping(value = "scUpdate", method = RequestMethod.POST)
    @ApiOperation(value = "数据",notes = "修改")
    public Result xgPatient(SccPatient sccPatient){
        System.out.println("sccPatient="+sccPatient);
        int add=SccServiceImpl.scUpdate(sccPatient);
        if (add>0){
            System.out.println("修改成功");
        }else{
            System.out.println("修改失败");
        }
        return Result.ok(ResultCode.SUCCESS,add);
    }

    @ApiOperation(value = "添加检测数据",notes = "添加",httpMethod ="GET")
    @RequestMapping(value = "mdeInsert", method = RequestMethod.GET)
    public Result MdeInsert(SccMedicalResult sccMedicalResult){
        System.out.println(sccMedicalResult);
        int add=SccServiceImpl.sccMedInsert(sccMedicalResult);
        if (add>0){
            System.out.println("添加成功");
        }else{
            System.out.println("添加失败");
        }
        return Result.ok(ResultCode.SUCCESS,add);
    }

    @RequestMapping(value = "FdSelect1", method = RequestMethod.GET)
    @ApiOperation(value = "查询用户", notes = "根据条件查询", httpMethod = "GET")
    public Result FdSelect(SccDrugstore sccDrugstore) throws  Exception{

        List<SccDrugstore> sdv1 = SccServiceImpl.FdSelect(sccDrugstore);
        return Result.ok(ResultCode.SUCCESS,sdv1);

    }
    @RequestMapping(value = "{patientId}", method = RequestMethod.GET)
    @ApiOperation(value = "检测结果ID", notes = "根据条件查询", httpMethod = "GET")
    public Result sccMde(@PathVariable int patientId) throws  Exception{
        System.out.println("============"+patientId);
        List<PRS> sdv1 = SccServiceImpl.sccMde(patientId);
        System.out.println("sssssssss"+sdv1);
        return Result.ok(ResultCode.SUCCESS,sdv1);

    }

    @RequestMapping(value = "sccMde1", method = RequestMethod.GET)
    @ApiOperation(value = "检测结果", notes = "根据条件查询", httpMethod = "GET")
    public Result sccMde1() throws  Exception{
        List<PRS> sdv1 = SccServiceImpl.sccMde1();
        System.out.println("sssssssss"+sdv1);
        return Result.ok(ResultCode.SUCCESS,sdv1);

    }

}
